-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decreases switch statements and deprecates BytesMessageEncoder #250
Conversation
efaeceb
to
bc45f62
Compare
case JSON: | ||
return JSON_V2; | ||
case PROTO3: | ||
throw new UnsupportedOperationException("PROTO3 is not yet a built-in encoder"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool thing is that I have a pending change to support this. However, anyone using forEncoding
could update into it without prior knowledge.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
152423f
to
3d1d869
Compare
seems like spring boot need to release soon, so I will check on this now. hopefully, looks ok to the team, but if you have a chance to take a look, please do! |
Here are some notable diffs. - HttpSender() {
- super(Encoding.JSON);
+ HttpSender(Encoding encoding) {
+ super(encoding);
}
@Override
@@ -74,7 +74,7 @@ abstract class HttpSender extends BytesMessageSender.Base {
if (this.closed) {
throw new ClosedSenderException();
}
- byte[] body = BytesMessageEncoder.JSON.encode(encodedSpans);
+ byte[] body = this.encoding.encode(encodedSpans);
HttpHeaders headers = getDefaultHeaders();
if (needsCompression(body)) {
body = compress(body);
@@ -86,7 +86,7 @@ abstract class HttpSender extends BytesMessageSender.Base {
HttpHeaders getDefaultHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.set("b3", "0");
- headers.set("Content-Type", "application/json");
+ headers.set("Content-Type", this.encoding.mediaType());
return headers;
} @Bean
@ConditionalOnMissingBean(value = MutableSpan.class, parameterizedContainer = BytesEncoder.class)
@ConditionalOnEnabledTracing
- BytesEncoder<MutableSpan> braveSpanEncoder() {
- return new JsonV2Encoder();
+ BytesEncoder<MutableSpan> braveSpanEncoder(Encoding encoding) {
+ return MutableSpanBytesEncoder.forEncoding(encoding);
}
@Bean
@@ -157,8 +158,8 @@ class ZipkinConfigurations {
@Bean
@ConditionalOnMissingBean(value = Span.class, parameterizedContainer = BytesEncoder.class)
@ConditionalOnEnabledTracing
- BytesEncoder<Span> zipkinSpanEncoder() {
- return SpanBytesEncoder.JSON_V2;
+ BytesEncoder<Span> zipkinSpanEncoder(Encoding encoding) {
+ return SpanBytesEncoder.forEncoding(encoding);
} |
I noticed in our senders and reporters there were multiple internal
switch
statements to get functions for a specific encoding. This is worse externally for zipkin-reporter-brave, as call sites need to duplicate switch statements, and also update them in order to allow another encoding. This is the case with PROTO3, for example, which is not yet supported for brave spans.Here are the main changes:
Encoding.encode(List<byte[]>)
from the now deprecatedBytesMessageEncoder
.Encoding.mediaType()
, useful in internal and external HTTP senders.SpanBytesEncoder.forEncoding(Encoding)
to reduce redundant switch logic.MutableSpanBytesEncoder.forEncoding(Encoding)
for BraveMutableSpanBytesEncoder.create(Encoding, Tag<Throwable>)
for Brave users who want an alt error tag.With these changes in place, external senders such as those defined in spring-boot, can inherit sensible defaults without maintenance.
This acknowledges some specialized senders (such as okhttp) won't use
Encoding.encode(List<byte[]>)
. However, this change makes commodity senders a lot easier to write and configure, as they can now be driven by justEncoding
and an endpoint.